package com.smf.lsc.authorization.security.captcha.config;

import java.util.Properties;

import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.google.code.kaptcha.impl.DefaultKaptcha;
import com.google.code.kaptcha.util.Config;
import com.smf.lsc.authorization.security.captcha.util.CodeProperties;

/**
 * 验证码配置
 * Created on 2021/11/19.
 *
 * @author ln
 * @since 1.0
 */
@Configuration
@EnableConfigurationProperties(CodeProperties.class)
public class CodeConfig {
	private static Properties props = new Properties();
	@Bean
	public DefaultKaptcha defaultKaptcha() throws Exception {
		// 创建DefaultKaptcha对象
		DefaultKaptcha defaultKaptcha = new DefaultKaptcha();
		
		// 读取配置文件
		try {
			props.load(CodeConfig.class.getClassLoader()
                .getResourceAsStream("kaptcha.properties"));
		}catch (Exception e) {
			e.printStackTrace();
		}
 
		// 将Properties文件设到DefaultKaptcha对象中
		defaultKaptcha.setConfig(new Config(props));
		return defaultKaptcha;
	}
}
